/* Viper Split# Compiler
 * Copyright (c) 2013 Split# Developers
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 */


/* NOTE: The above license DOES NOT APPLY to the Viper and GruntXProductions
 * namespace. Viper is released under the GNU General Public License v3
 */

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using GruntXProductions;

namespace SplitSharp
{
        public enum BoolOp
        {
                Equal,
                NotEqual,
                GreaterThan,
                LessThan
        }

        public class CodeElement : Token
        {

        }

        public class TryBody : CodeElement
        {
                public CodeBlock body;
                public CatchBody Catch;

        }

        public class CatchBody : CodeElement
        {
                public Declaration exception;
                public CodeBlock body;
        }

        public class Error : CodeElement
        {
                private string text;

                public Error (string msg)
                {
                        text = msg;
                        SplitSharp.Compiler.cgen.Errors.Add (text);
                }

                public override string ToString ()
                {
                        return text;
                }
        }

        public class Instance : CodeElement
        {
                public string Type;
                public FunctionCall Ctor;
                public string Name;
        }

        public class FixedArray : CodeElement
        {
                public string Name;
                public string Type;
                public int Size;
        }

        public class Declaration : CodeElement
        {
                public string Name;
                public string Type;
                public Assign Value = null;

        }

        public class CodeObject : CodeElement
        {
                public List<Function> methods = new List<Function> ();
                public List<Declaration> fields = new List<Declaration> ();
                public string Name = "";
        }

        public class Expression : CodeElement
        {
                public List<Token> tokens = new List<Token> ();
        }

        public class CodeBlock : CodeElement
        {
                public List<CodeElement> Body = new List<CodeElement> ();
        }

        public class IfStatement : CodeElement
        {
                public BooleanComparison Expression = new BooleanComparison ();
                public CodeBlock ifBody = new CodeBlock ();
                public CodeBlock elseBody = new CodeBlock ();
        }

        public class ArrayRetrieve : CodeElement
        {
                public string Variable;
                public List<Token> IndexExpression = new List<Token> ();
        }

        public class ArrayAssign : CodeElement
        {
                public string Variable;
                public List<Token> Index = new List<Token> ();
                public List<Token> Value = new List<Token> ();
        }

        public class MetaElement : CodeElement
        {
                public string Tag;
                public string Value;
        }

        public class AddressOf : CodeElement
        {
                public string Symbol;
        }

        public class ObjectAssign : CodeElement
        {
                public string Ref;
                public string Variable;
                public List<Token> Value = new List<Token> ();
        }

        public class PointerDereference : CodeElement
        {
                public Token Pointer;
        }

        public class ObjectCall : CodeElement
        {
                public string Ref;
                public string Name;
                public List<Expression> Arguments = new List<Expression> ();
        }

        public class Assign : CodeElement
        {
                public string Variable;
                public List<Token> Value = new List<Token> ();
        }

        public class ForStatement : CodeElement
        {
                public BooleanComparison Comparison;
                public CodeBlock forBody;
                public CodeElement Declaration;
                public CodeElement Operation;

        }

        public class inlineAsm : CodeElement
        {
                public string Asm;
        }

        public class BooleanComparison : CodeElement
        {
                public Expression Expression1 = new Expression ();
                public Expression Expression2 = new Expression ();
                public BoolOp Operation;
        }

        public class Function : CodeElement
        {
                public string Name;
                public string Type;
                public bool External = false;
                public List<Declaration> Arguments = new List<Declaration> ();
                public CodeBlock body;
        }

        public class Return : CodeElement
        {
                public List<Token> Value = new List<Token> ();
        }

        public class FunctionCall : CodeElement
        {
                public string Name;
                public List<Expression> Arguments = new List<Expression> ();
        }

        public class WhileStatement : CodeElement
        {
                public BooleanComparison Comparison;
                public CodeBlock whileBody;
        }
}

